package org.yu.api.register.data;

import net.minecraft.data.DataGenerator;
import net.minecraft.data.HashCache;
import net.minecraftforge.common.data.ExistingFileHelper;
import org.yu.api.register.LazyRecipe;
import org.yu.api.register.LazyRecipeSerializer;
import org.yu.api.register.LazyRegistry;


import javax.annotation.Nonnull;
import java.util.List;

public class LazyRecipeProvider extends LazyGeneratorBase{

    private final List<LazyRecipe> recipeHolders;
    public LazyRecipeProvider(LazyRegistry lazyRegistry, DataGenerator generator, ExistingFileHelper fileHelper, List<LazyRecipe> recipeHolder) {
        super(lazyRegistry, generator, fileHelper);
        this.recipeHolders = recipeHolder;
    }
    @SuppressWarnings({"all"})
    @Override
    public void run(@Nonnull HashCache pCache) {
        System.out.println("Will generate "+recipeHolders.size()+" recipes.");
        recipeHolders.forEach((lazyRecipe) -> {
            saveData(((LazyRecipeSerializer)lazyRecipe.getSerializer()).toJson(lazyRecipe),"recipes/"+lazyRecipe.getSerializer().getRegistryName().getPath()+"/",lazyRecipe.getId().getPath(),pCache);
        });
    }
    public static record LazyRecipeProviderHolder<T extends LazyRecipe>(String name,T recipe){ }
}
